-
Notifications
You must be signed in to change notification settings - Fork 530
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add options for uniqueness validations. Resolves #319 #333
base: core
Are you sure you want to change the base?
Conversation
This will break behaviour for people already using the Wasn't sure if we should handle that case as the |
@BenMorganIO @jhawthorn Could we hope that it sometimes will be merged? |
Don't custom paranoid gem.You can write: |
class Client < ActiveRecord::Base | ||
acts_as_paranoid | ||
|
||
validates :name, uniqueness: { paranoia: :with_deleted } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Don't custom paranoid gem.You can write:
validates :name, uniqueness: {conditions: ->{with_deleted}}
class Client < ActiveRecord::Base | ||
acts_as_paranoid without_default_scope: true | ||
|
||
validates :name, uniqueness: { paranoia: :without_deleted } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Don't custom paranoid gem.You can write:
validates :name, uniqueness: {conditions: ->{with_deleted}}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Don't custom paranoid gem.You can write:
validates :name, uniqueness: {conditions: ->{with_deleted}}
Doesn't work for me
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Doesn't work for me either in rails v4.2.10
using MySQL. Traced it a bit and I found that rails wasn't actually removing the scope via the unscope
method because of the way the relation query is set up. By the time it hits here, the relation is wrapped and chained with an AND
query. It doesn't get through this case statement to actually remove the column from the scope because the relation rel
is a Arel::Nodes::And
at that point.
I just ended up making my own validator which manually checked for uniqueness against the unscoped records to move forward.
Paranoia doesn't support unique validation including deleted records: rubysherpas/paranoia#333 We use a custom validator, ScopedUniquenessValidator to avoid the issue
Paranoia doesn't support unique validation including deleted records: rubysherpas/paranoia#333 We use a custom validator, ScopedUniquenessValidator to avoid the issue
Paranoia doesn't support unique validation including deleted records: rubysherpas/paranoia#333 We use a custom validator, ScopedUniquenessValidator to avoid the issue
Paranoia doesn't support unique validation including deleted records: rubysherpas/paranoia#333 We use a custom validator, ScopedUniquenessValidator to avoid the issue
For with_default_scope add a
paranoia: :with_deleted
option when you want to ensure uniqueness on all records.For without_default_scope add a
paranoia: :without_deleted
option when you want to ensure uniqueness on only non-deleted records.